﻿Public Class UsbCheck


    '''检查加密锁的有关情况
    Public Function DoCheck() As Boolean

        Dim ready As Boolean = False




        Dim bRet As Boolean

        Dim info As String

        Dim RealLen As Integer
        Dim tBuf() As Byte
        ReDim tBuf(8)

        Dim edc As ELE_DEVICE_CONTEXT

        edc.ulSize = Len(edc)

        'open device
        bRet = EleOpenFirstDevice(0, 0, 0, ELE_SHARE_MODE, edc)
        If bRet Then
            info = "访问加密锁"
            'set led down
            bRet = EleControl(edc, ELE_SET_LED_DOWN, 0, 0, 0, 0, RealLen)
            If bRet Then
                info = "set led down success"
            Else

            End If

            Dim sIn As String
            Dim Output(1023) As Byte

            sIn = ""
            info = "" & sIn
            bRet = EleExecute(edc, "gg", sIn, Len(sIn), Output(0), 1024, RealLen)
            If bRet Then
                '在这里分析读取的加密数据
                Dim A0 As Byte = Output(0)
                Dim A1 As Byte = Output(1)
                Dim A2 As Byte = Output(2)
                Dim A3 As Byte = Output(3)
                Dim A4 As Byte = Output(4)
                Dim A5 As Byte = Output(5)
                Dim A6 As Byte = Output(6)
                Dim A7 As Byte = Output(7)
                Dim A8 As Byte = Output(8)
                Dim A9 As Byte = Output(9)
                'If A0 <> 42 Then
                '    MessageBox.Show("对不起，请检查您插入的加密锁是否为正版授权的加密锁！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If
                'If A1 <> 13 Then
                '    MessageBox.Show("对不起，请检查您插入的加密锁是否为正版授权的加密锁！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If
                'If A2 <> 8 Then
                '    MessageBox.Show("对不起，请检查您插入的加密锁是否为正版授权的加密锁！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If
                'If A3 <> 28 Then
                '    MessageBox.Show("对不起，请检查您插入的加密锁是否为正版授权的加密锁！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If
                'If A4 <> 92 Then
                '    MessageBox.Show("对不起，请检查您插入的加密锁是否为正版授权的加密锁！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If
                'If A5 <> 21 Then
                '    MessageBox.Show("对不起，请检查您插入的加密锁是否为正版授权的加密锁！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If
                'If A6 <> 12 Then
                '    MessageBox.Show("对不起，请检查您插入的加密锁是否为正版授权的加密锁！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If
                'If A7 <> 52 Then
                '    MessageBox.Show("对不起，请检查您插入的加密锁是否为正版授权的加密锁！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If
                'If A8 <> 92 Then
                '    MessageBox.Show("对不起，请检查您插入的加密锁是否为正版授权的加密锁！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If
                'If A9 <> 86 Then
                '    MessageBox.Show("对不起，请检查您插入的加密锁是否为正版授权的加密锁！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                '    Exit Sub
                'End If

                ready = False


            Else


                bRet = EleExecute(edc, "gettime", sIn, Len(sIn), Output(0), 1024, RealLen)
                If bRet Then
                    '在这里分析读取的时间
                    Dim ucHour As Byte = Output(2)
                    Dim ucDay As Byte = Output(3)
                    Dim ucMonth As Byte = Output(5) + 1
                    Dim ucYear As Byte = Output(7)
                    If ucYear <> 110 Then
                        MessageBox.Show("对不起，试用期已过，请购买正式版软件！", "试用提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                        ready = False
                    Else
                        ready = True
                    End If

                    '这里直接给用到2010年结束

                    'If ucMonth >= 10 Then
                    '    MessageBox.Show("对不起，试用期已过，请购买正式版软件！", "试用提示", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                    '    Exit Function
                    'End If
                    'If ucMonth >= 9 Then
                    '    MessageBox.Show("您的试用期已不足1个月，请购买正式版软件！", "试用提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk)
                    'End If


                Else
                    MessageBox.Show("不能正确访问加密锁，请检查是否已经插入加密锁。", "访问加密锁失败", MessageBoxButtons.OK, MessageBoxIcon.Error)

                End If




            End If

            'set led up
            bRet = EleControl(edc, ELE_SET_LED_UP, 0, 0, 0, 0, RealLen)
            If bRet Then
                info = "set led up success"
            Else
                MessageBox.Show("不能正确访问加密锁，请检查是否已经插入加密锁。", "访问加密锁失败", MessageBoxButtons.OK, MessageBoxIcon.Error)
                Return False
            End If
            'close device
            bRet = EleClose(edc)
            If bRet Then
                info = "close device success"
            Else
                MessageBox.Show("不能正确访问加密锁，请检查是否已经插入加密锁。", "访问加密锁失败", MessageBoxButtons.OK, MessageBoxIcon.Error)

                Return False
            End If


            Return ready

        Else


            MessageBox.Show("不能正确访问加密锁，请检查是否已经插入加密锁。", "访问加密锁失败", MessageBoxButtons.OK, MessageBoxIcon.Error)

            Return False





        End If
    End Function

End Class
